<template>
  <div>
    <!-- 需求计划汇总查询N+1 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="addHandle(2)">下发</multiuse-button>
      </template>
    </FilterTable>

    <BaseDialog :visible.sync="issearch" :title="'基本信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher :rowData="formData" @close="emitcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="visible" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <childrenModel :rowData="formData" @close="emitcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="isiue" :title="'基本信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <isiue :rowData="formData" @close="emitcloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import ownerSeacher from './ownerSeacher';
import childrenModel from './childrenModel';
import isiue from './isiue';
export default {
  name: 'TemplateDistribution',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {},
      fetchApi: () => {},
      formData: {},
      visible: false,
      issearch: false,
      isiue: false
    };
  },
  components: {
    ownerSeacher,
    childrenModel,
    isiue
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '事业部',
          fieldName: 'syb',
          placeholder: '请选择',
          itemList: []
        },

        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'jxsdm1',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'jxsmc',
          placeholder: '请选择'
        },
        {
          type: 'SELECT',
          label: '车系名称',
          fieldName: 'cxmc',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '车型名称',
          fieldName: 'cxmc',
          placeholder: '请选择',
          itemList: []
        },

        {
          type: 'DATE',
          label: '月份',
          fieldName: 'yf',
          placeholder: '请选择',
          dateType: 'month'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '事业部',
          dataIndex: 'syb',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '办事处',
          dataIndex: 'bsc',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '经销商代码',
          dataIndex: 'jxsdm',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商',
          dataIndex: 'jxsmc',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '品牌名称',
          dataIndex: 'zcbmms',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系名称',
          dataIndex: 'zcbm',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '车型名称',
          dataIndex: 'cxmc2',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '月份',
          dataIndex: 'yf',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '任务数量(批售)',
          dataIndex: 'rwslps',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '任务数量(终端)',
          dataIndex: 'rwslzd',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '下发人',
          dataIndex: 'xfr',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '下发日期',
          dataIndex: 'xfrq',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建日期',
          dataIndex: 'cjrq',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建人',
          dataIndex: 'cjr',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    selectChangeHandle(row) {},
    seacherFun() {
      this.issearch = true;
    },
    addHandle(data) {
      this.isiue = true;
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    editHandle(data) {
      this.visible = true;
    },
    emitcloseHandler() {
      this.visible = false;
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    }
  }
};
</script>
